package se.energimyndigheten.lampguiden.bulbreplacement;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

import se.energimyndigheten.lampguiden.R;

public class ExplainFragment extends Fragment {
    public static final String EXTRA_HTML_PATH = "html_path";
    public static final String HTML_PATH = "Lamptyper/sv_";
    public static final String HTML_404 = "file::///android_asset/404.html";

    private static final String TAG = ExplainFragment.class.getSimpleName();
    private String mPath;
    private WebView mWebView;
    
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		mPath = getArguments().getString(EXTRA_HTML_PATH);
		return inflater.inflate(R.layout.webview_activity, container, false);
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		final FragmentActivity parent = getActivity();
        mWebView = (WebView) parent.findViewById(R.id.webview);
		loadHtmlFile();
	}
	
    private void loadHtmlFile() {
        String path = mPath != null ? mPath : HTML_404;
        //Log.v(TAG, "loadHtmlFile - path: " + path);
        mWebView.loadUrl(path);
    }
}
